<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>学生管理--错题收藏</title>
    <meta name="description" content="这是一个 index 页面">
    <meta name="keywords" content="index">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="renderer" content="webkit">
    <meta http-equiv="Cache-Control" content="no-siteapp" />
    <link rel="icon" type="image/png" href="assets/i/favicon.png">
    <link rel="apple-touch-icon-precomposed" href="assets/i/app-icon72x72@2x.png">
    <meta name="apple-mobile-web-app-title" content="Amaze UI" />
    <link rel="stylesheet" href="assets/css/amazeui.min.css" />
    <link rel="stylesheet" href="assets/css/amazeui.datatables.min.css" />
    <link rel="stylesheet" href="assets/css/bootstrap.min.css">
    <link rel="stylesheet" href="assets/css/app.css">
    <link rel="stylesheet" href="assets/css/gb_my.css">
    <link rel="stylesheet" href="assets/css/font-awesome.css">
    <link rel="stylesheet" href="assets/css/bootstrap-reset.css">
    <link rel="stylesheet" href="assets/css/easydropdown.css">
    <link rel="stylesheet" href="assets/css/layer-animate.css">
</head>
<body data-type="chart">
<div class="am-g tpl-g">
    <!--头部-->
    <nav class="navbar navbar-default top-navbar">
        <div class="navbar-header">
            <a class="navbar-brand waves-effect waves-dark" href="javascript:;">
                <img src="assets/img/logo.png" alt="">
                <strong>轻课网考试系统</strong>
            </a>
            <div id="sideNav" href="">
                <i class="mulv QK QK-mulu"></i>
            </div>
        </div>
        <ul class="nav navbar-top-links navbar-right aaa">
            <li>
                <a id="down_" class="sign-out dropdown-button waves-effect waves-dark" href="javascript:;">
                    <span class="am-icon-sign-out"></span> 退出
                </a>
            </li>
            <li>
                <a class="dropdown-button waves-effect waves-dark" href="javascript:;"><b>欢迎你, <span class="userName"></span> </b></a>
            </li>
        </ul>
    </nav>
    <!--导航栏-->
    <nav class="navbar-default navbar-side">
        <div class="sidebar-collapse">
            <!--用户头像-->
            <div class="tpl-sidebar-user-panel">
                <div class="tpl-user-panel-slide-toggleable">
                    <div class="tpl-user-panel-profile-picture">
                        <img src="assets/img/user04.png" alt="">
                    </div>
                </div>
            </div>
            <dl class="list_dl">
                <dt class="list_dt">
                    <a href="index.html">
                        <span class="QK1 start_before"></span>
                        <p>学生平台</p>
                    </a>
                </dt>
                <dt class="list_dt">
                    <span class="QK1 topic_before"></span>
                    <p>我的考试</p>
                    <i class="QK1 list_dt_icon"></i>
                </dt>
                <dd class="list_dd">
                    <ul>
                        <li class="list_li">
                            <a href="student.html">我的试卷</a>
                        </li>
                        <li class="list_li">
                            <a href="examRecords.html">考试记录</a>
                        </li>
                    </ul>
                </dd>
                <dt class="list_dt">
                    <span class="QK1 paper_before"></span>
                    <p>自我检测</p>
                    <i class="QK1 list_dt_icon"></i>
                </dt>
                <dd class="list_dd">
                    <ul>
                        <li class="list_li">
                            <a href="testing.html">自我检测</a>
                        </li>
                        <li class="list_li">
                            <a href="error.html">检测结果</a>
                        </li>
                    </ul>
                </dd>
                <dt id="open" class="list_dt">
                    <span class="QK1 user_before"></span>
                    <p>个人管理</p>
                    <i class="QK1 list_dt_icon"></i>
                </dt>
                <dd class="list_dd" style="display: block">
                    <ul>
                        <li class="list_li">
                            <a href="personalData.html">个人资料</a>
                        </li>
                        <li class="list_li" id="style_li_a">
                            <a href="collection.html">题目收藏</a>
                        </li>
                    </ul>
                </dd>
                <dt class="list_dt">
                    <span class="QK1 chat_before"></span>
                    <p>聊天室</p>
                    <i class="QK1 list_dt_icon"></i>
                </dt>
                <dd class="list_dd">
                    <ul>
                        <li class="list_li">
                            <a href="chatroom.html">聊天室</a>
                        </li>
                    </ul>
                </dd>
            </dl>
        </div>
    </nav>
    <!-- 内容区域 -->
    <div id="page-wrapper">
        <div class="row">
            <div class="col-lg-12">
                <section class="panel">
                    <header class="panel-heading">
                        <button type="button" class="btn btn-success btn-sm add_clazz btn_my" id="back">
                            <span class="QK1 QK-fanhui1"></span>&nbsp;&nbsp;返回
                        </button>
                    </header>
                    <div class="panel-body">
                        <table width="100%" class="table table-bordered table-striped table-condensed table_question">
                            <thead>
                            <tr>
                                <th>编号</th>
                                <th>题库</th>
                                <th>类型</th>
                                <th>题干</th>
                                <th>操作</th>
                            </tr>
                            </thead>
                            <tbody id="wraper">

                            </tbody>
                        </table>
                        <ul class="box" style="display: none">
                            <li class="prev"></li>
                            <li>
                                <ul class="box2"></ul>
                            </li>
                            <li class="next"></li>
                            <li class="all_number numb"></li>
                        </ul>
                        <div class="loading">
                            <span></span>
                            <span></span>
                            <span></span>
                            <span></span>
                            <span></span>
                        </div>
                    </div>
                    <div id="myModal20" class="modal" data-easein="slideDownBigIn" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
                        <div class="modal-dialog center_modal">
                            <div class="modal-content">
                                <div class="modal-header title_header">
                                    <button type="button" class="close deleteall" data-dismiss="modal" aria-hidden="true">×</button>
                                    <!--<h4 class="modal-title">题干</h4>-->
                                </div>
                                <div class="modal-body" id="detailcontent">
                                    <ul></ul>
                                </div>
                                <div class="modal-footer">
                                    <button class="btn btn-default deleteall" data-dismiss="modal" aria-hidden="true">关闭</button>
                                </div>
                            </div>
                        </div>
                    </div>
                </section>
            </div>
        </div>
    </div>
</div>
</body>
</html>
<script src="assets/js/jquery.min.js"></script>
<script src="assets/js/theme.js"></script>
<script src="assets/js/easydropdown.js"></script>
<script src="assets/js/html5sv.js"></script>
<script type="text/javascript" src="assets/js/jquery.cookie.js"></script>
<script src="assets/js/bootstrap.min.js"></script>
<script src="assets/js/velocity.min.js"></script>
<script src="assets/js/velocity.ui.min.js"></script>
<script src="assets/js/amazeui.min.js"></script>
<script src="assets/js/amazeui.datatables.min.js"></script>
<script src="assets/js/dataTables.responsive.min.js"></script>
<script src="assets/js/student.js"></script>
<script src="assets/js/method.js"></script>
<script>
    $('.loading').css('display' , 'block');
    $('.box').css('display' , 'none');
    $("#back").click(function() {
        window.location.href = "collection.html";
    });
    $(document).ready(function () {
        //题库id
        var question_id = window.location.search.split("=")[1];
//        console.log(question_id);
        var storage = window.localStorage;
        var user_id = storage["uid"];
        var class_id = storage["class_id"];
        var user_name = storage["user_name"];

        $.ajax({
            url: localApi + "/QuestionFavorite/DbNameAndNumber",
            type: "get",
            async: false,
            data: {
                apikey:'1',
                uid:user_id
            },
            success:function (result) {
                if(result.data == 'error'){
                    $('.loading').css('display' , 'none');
                    $('.panel-body').empty();
                    var add_empty = '<p>暂无收藏的试题！！！</p>';
                    $('.panel-body').append(add_empty);
                    $('.panel-body').addClass('add_empty_style');
                }else{
                    $.each(result.data , function (n , item) {
                        if(item.dbid != question_id){
                            $('.loading').css('display' , 'none');
                            $('.panel-body').empty();
                            var add_empty = '<p>暂无收藏的试题！！！</p>';
                            $('.panel-body').append(add_empty);
                            $('.panel-body').addClass('add_empty_style');
                        }else{
                            $('.loading').css('display' , 'none');
                            $('.box').css('display' , 'flex');
                            getPage(1);
                        }
                    });
                }
            }
        });
        var label_title;
        if(question_id == '16'){
            label_title = '<span class="label label-primary">Java收藏题库</span>';
            $('.panel-heading').prepend(label_title);
        }
        if(question_id == '18'){
            label_title = '<span class="label label-primary">数据库收藏题库</span>';
            $('.panel-heading').prepend(label_title);
        }
        if(question_id == '19'){
            label_title = '<span class="label label-primary">web收藏题库</span>';
            $('.panel-heading').prepend(label_title);
        }
        if(question_id == '20'){
            label_title = '<span class="label label-primary">框架整合收藏题库</span>';
            $('.panel-heading').prepend(label_title);
        }
        //翻页
        function getPage(pn) {
            $.ajax({
                url: localApi + "/QuestionFavorite/DbNameAndNumber",
                type: "get",
                async: false,
                data: {
                    apikey:'1',
                    uid:user_id
                },
                success: function(result) {
                    console.log(result.data);
                    $.each(result.data , function (n , item) {
                        if(item.dbid == question_id){
                            count = item.number;
                            var dataCount = count; //总数据条数
                            var pageSize = 5; //每页显示条数
                            var pageCount = Math.ceil(dataCount / pageSize); //总页数
                            if(pn == 0 || pn > pageCount) {
                                return;
                            }
                            var ul = $("#wraper");
                            ul.empty();
                            //console.log(pageCount+"..."+pn)
                            paintPage(pageCount, pn); //绘制页码
                            $.ajax({
                                url: localApi + "/QuestionFavorite/index",
                                type: 'get',
                                async: false,
                                data: {
                                    apikey: '1',
                                    limit: '10',
                                    offset: ((pn - 1) * 10),
                                    uid:user_id,
                                    dbid:question_id
                                },
                                success: function(result) {
//                                    console.log(result.data);
                                    $.each(result.data, function(n, item) {
                                        if(item.questionCollection.questionWithBLOBs.qtype == 1) {
                                            var qtype = "单选"
                                        } else if(item.questionCollection.questionWithBLOBs.qtype == 2) {
                                            qtype = "多选"
                                        } else if(item.questionCollection.questionWithBLOBs.qtype == 3) {
                                            qtype = "填空"
                                        } else if(item.questionCollection.questionWithBLOBs.qtype == 4) {
                                            qtype = "判断"
                                        } else {
                                            qtype = "问答"
                                        }
                                        var dbName = item.questionCollection.questionWithBLOBs.questionDb.dname;
                                        var content = item.questionCollection.questionWithBLOBs.content;
                                        var content_s = content.replace(/<[^>]+>/g, ""); //去除html标签
                                        var content_ss = content_s.replace('&nbsp;', "");
                                        var coulmn = '<tr class="even gradeX student add_p5 delete_some"><td class="qidnew">' + item.id + '</td><td>' + dbName + '</td><td>' + qtype + '</td><td>' + content_ss + '</td>';
                                        coulmn += '<td class="operation"><div class="tpl-table-black-operation">' + '<a href="#myModal20" ' +
                                            'data-toggle="modal" class="tpl-table-black-operation-del button button--aylen detail" value=' + item.questionCollection.questionWithBLOBs.id + '><i class="QK1 QK-xiangqing spacing_detail">' +
                                            '</i>详情</a>' +
                                            '<a href="javascript:;" value=' + item.id + ' class="delete_this tpl-table-black-operation-del button button--aylen" >' +
                                            '<i class="QK1 QK-shanchu spacing_detail"></i>删除</a>' +
                                            '</div></td></tr>';
                                        $("#wraper").append(coulmn);
                                    });
                                    $('.gradeX').find('td:nth-child(2)').children(':first-child').siblings().remove();
                                    $('.delete_some').find('td:nth-child(3)').children(':first-child').nextAll().remove()
                                }
                            });
                        }
                    });
                }
            });
        }
        //绘制页码
        function paintPage(number, currNum) //number 总页数,currNum 当前页
        {
            var pageUl = $(".box");
            var nextLi = $('.next'),
                prevLi = $('.prev'),
                pageUl2 = $('.box2'),
                pageNumber = $('.all_number');
            nextLi.empty();
            prevLi.empty();
            pageUl2.empty();
            pageNumber.empty();
            var ulDetail = "";

            //上一页
            if(currNum > 1){
                prevLi.append('<a href="javascript:getPage(' + parseInt(currNum - 1) + ')" class="prevPage"><上一页</a>');
            }else{
                prevLi.remove('.prevPage');
                prevLi.append('<span class="disabled"><上一页</span>');
            }
            //中间页码
            if(currNum != 1 && number >= 4 && number != 4 && currNum >= 4){
                pageUl2.append('<li class="numb"><a href="javascript:getPage(1)" class="tcdNumber">'+1+'</a></li>');
            }
            if(currNum-2 > 2 && currNum <= number && number > 5){
                pageUl2.append('<li class="li_span"><span>...</span></li>');
            }
            var start = currNum -2,end = currNum+2;
            if((start > 1 && currNum < 4)||currNum == 1){
                end++;
            }
            if(currNum > number-4 && currNum >= number){
                start--;
            }
            for (;start <= end; start++) {
                if(start <= number && start >= 1){
                    if(start != currNum){
                        pageUl2.append('<li class="numb"><a href="javascript:getPage('+ start +')" class="tcdNumber">'+ start +'</a></li>');
                    }else{
                        pageUl2.append('<li class="numb choose"><span class="current">'+ start +'</span></li>');
                    }
                }
            }
            if(currNum + 2 < number - 1 && currNum >= 1 && number > 5){
                pageUl2.append('<li class="li_span"><span>...</span></li>');
            }
            if(currNum != number && currNum < number -2  && number != 4){
                pageUl2.append('<li class="numb"><a href="javascript:getPage('+ number +')" class="tcdNumber">'+number+'</a></li>');
            }
            //下一页
            if(currNum <number){
                nextLi.append('<a href="javascript:getPage(' + parseInt(currNum + 1) + ')" class="nextPage">下一页></a>');
            }else{
                nextLi.remove('.nextPage');
                nextLi.append('<span class="disabled">下一页></span>');
            }
            pageNumber.append('<span class="pagecount">共'+number+'页</span>');
            if(currNum == 1) {
                $('.prev').removeClass('selected_paging').removeClass('hover').css('cursor', 'text').find('a').css('cursor', 'text');
            }
            if(currNum == 1 && number > 1) {
                $('.next').addClass('selected_paging');
            }
            if(currNum == number) {
                $('.next').removeClass('selected_paging').removeClass('hover').css('cursor', 'text').find('a').css('cursor', 'text');
            }
            if(currNum == number && currNum > 1) {
                $('.prev').addClass('selected_paging');
            }
            if(currNum !== number && currNum > 1) {
                $('.prev').addClass('selected_paging');
                $('.next').addClass('selected_paging');
            }
            $('.choose').addClass('selected_paging').siblings().removeClass('selected_paging').addClass('hover');
        }
    });
    //试题详情
    $(document).on('click', '.detail', function() {
        var questionid = $(this).attr("value");
        $.ajax({
            type: "get",
            url: localApi + "/QuestionWithBLOBs/get",
            data: {
                id: questionid,
                apikey: '1'
            },
            success: function(result) {
//			    console.log(result.data);
                var content =  result.data.content;
                var content_s = content.replace(/<[^>]+>/g, ""); //去除html标签
                var content_ss = content_s.replace('&nbsp;', "");
                var title = '<h4 class="modal-title">'+ content_ss +'</h4>';
                $('.title_header').append(title);
                $.each(result.data.questionOptions, function(n, item) {
                    if(item.salisa == 'A') {
                        var coulmn = '<li><strong>' + item.salisa + '.</strong>&nbsp;&nbsp;<P>' + item.soption + '</P></li>'
                        $("#detailcontent").select("ul").append(coulmn)
                    }
                });
                $.each(result.data.questionOptions, function(n, item) {
                    if(item.salisa == 'B') {
                        var coulmn = '<li><strong>' + item.salisa + '.</strong>&nbsp;&nbsp;<P>' + item.soption + '</P></li>'
                        $("#detailcontent").select("ul").append(coulmn)
                    }
                });
                $.each(result.data.questionOptions, function(n, item) {
                    if(item.salisa == 'C') {
                        var coulmn = '<li><strong>' + item.salisa + '.</strong>&nbsp;&nbsp;<P>' + item.soption + '</P></li>'
                        $("#detailcontent").select("ul").append(coulmn)
                    }
                });
                $.each(result.data.questionOptions, function(n, item) {
                    if(item.salisa == 'D') {
                        var coulmn = '<li><strong>' + item.salisa + '.</strong>&nbsp;&nbsp;<P>' + item.soption + '</P></li>'
                        $("#detailcontent").select("ul").append(coulmn)
                    }
                });
                $.each(result.data.questionOptions, function(n, item) {
                    if(item.salisa == 'E') {
                        var coulmn = '<li><strong>' + item.salisa + '.</strong>&nbsp;&nbsp;<P>' + item.soption + '</P></li>'
                        $("#detailcontent").select("ul").append(coulmn)
                    }
                });
                $.each(result.data.questionOptions, function(n, item) {
                    if(item.salisa == 'H') {
                        var coulmn = '<li><strong>' + item.salisa + '.</strong>&nbsp;&nbsp;<P>' + item.soption + '</P></li>'
                        $("#detailcontent").select("ul").append(coulmn)
                    }
                });
                $.each(result.data.questionOptions, function(n, item) {
                    if(item.salisa == 'G') {
                        var coulmn = '<li><strong>' + item.salisa + '.</strong>&nbsp;&nbsp;<P>' + item.soption + '</P></li>'
                        $("#detailcontent").select("ul").append(coulmn)
                    }
                });
                var analysis = "<strong>正确答案:"+ result.data.skey +"</strong><p>解析: "+ result.data.keydesc +"</p>"
                $('.modal-body').append(analysis);
            },
            error: function() {
                alert("123")
            }
        });
    });
    //关闭
    $(document).on('click', '.deleteall', function() {
        $('.modal-title').empty();
        $("#detailcontent").select("ul").empty();
    });
    //删除试题
    $(document).on('click' , '.delete_this' , function () {
        var questionid = $(this).attr("value");
        $.ajax({
            type: "post",
            url: localApi + "/QuestionFavorite/delete",
            data: {
                id: questionid,
                apikey: '1'
            },
            success:function (result) {
                if(result.msg == 'success'){
                    var obj={
                        type:"slideFromBottom",
                        confirm:"true",
                        content:"<div>删除成功",
                        btn:["","OK"]
                    };
                    method.msg_layer(obj);
                    $('.layer-commit').click(function () {
                        window.location.reload();
                    });
                    console.log('删除成功');
                }else{
                    console.log('失败了');
                    var obj={
                        type:"layerFadeIn",
                        close:"true",
                        content:"<div>删除失败",
                        btn:["取消",""]
                    };
                    method.msg_layer(obj);
                    $('.layer-commit').remove();
                }
            },
            error:function (result) {
                console.log('失败了');
                var obj={
                    type:"layerFadeIn",
                    close:"true",
                    content:"<div>系统错误,删除失败",
                    btn:["取消",""]
                };
                method.msg_layer(obj);
                $('.layer-commit').remove();
            }
        })
    })
</script>
<script type="text/javascript">
    // add the animation to the popover
    $('a[rel=popover]').popover().click(function(e) {
        e.preventDefault();
        var open = $(this).attr('data-easein');
        if (open == 'shake') {
            $(this).next().velocity('callout.' + open);
        } else if (open == 'pulse') {
            $(this).next().velocity('callout.' + open);
        } else if (open == 'tada') {
            $(this).next().velocity('callout.' + open);
        } else if (open == 'flash') {
            $(this).next().velocity('callout.' + open);
        } else if (open == 'bounce') {
            $(this).next().velocity('callout.' + open);
        } else if (open == 'swing') {
            $(this).next().velocity('callout.' + open);
        } else {
            $(this).next().velocity('transition.' + open);
        }

    });

    // add the animation to the modal
    $(".modal").each(function(index) {
        $(this).on('show.bs.modal', function(e) {
            var open = $(this).attr('data-easein');
            if (open == 'shake') {
                $('.modal-dialog').velocity('callout.' + open);
            } else if (open == 'pulse') {
                $('.modal-dialog').velocity('callout.' + open);
            } else if (open == 'tada') {
                $('.modal-dialog').velocity('callout.' + open);
            } else if (open == 'flash') {
                $('.modal-dialog').velocity('callout.' + open);
            } else if (open == 'bounce') {
                $('.modal-dialog').velocity('callout.' + open);
            } else if (open == 'swing') {
                $('.modal-dialog').velocity('callout.' + open);
            } else {
                $('.modal-dialog').velocity('transition.' + open);
            }

        });
    });
</script>
<script>
    $(document).ready(function() {
        $('#back').click(function () {
            window.location.href = "examRecords.html";
        });
        $(".list_dt").on("click", function() {
            $('.list_dd').stop();
            $(this).siblings("dt").removeAttr("id");
            if($(this).attr("id") == "open") {
                $(this).removeAttr("id").siblings("dd").slideUp();
            } else {
                $(this).attr("id", "open").next().slideDown().siblings("dd").slideUp();
            }
        });
    });
</script>
<script>
    $(document).ready(function() {
        $(".dropdown-button").dropdown();
        $("#sideNav").click(function() {
            if($(this).hasClass('closed')) {
                $('.navbar-side').animate({
                    left: '0px'
                });
                $(this).removeClass('closed');
                $('#page-wrapper').animate({
                    'margin-left': '260px'
                });
            } else {
                $(this).addClass('closed');
                $('.navbar-side').animate({
                    left: '-260px'
                });
                $('#page-wrapper').animate({
                    'margin-left': '0px'
                });
            }
        });
    });
    $(".dropdown-button").dropdown();
</script>